package com.cherrish.demo.collections;

import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;

/**
 * @author cherrish
 * @time 2019-04-09 11:35
 * @name MyLinkedList
 * @desc:
 */
public class MyLinkedList<T> implements Iterable<T>{
    private int size;
    private int modCount = 0;

    private Node<T> first;
    private Node<T> last;

    private void doClear(){
        size = 0;
    }

    public boolean add(T data){
        final Node<T> l = last;
        final Node<T> newNode = new Node<>(l, data, null);
        last = newNode;
        if (l == null) {
            first = newNode;
        }else {
            l.next = newNode;
        }
        size++;
        modCount++;
        return true;
    }

    private static class Node<T>{
        private T data;
        private Node<T> prev;
        private Node<T> next;

        public Node(Node<T> prev, T data, Node<T> next) {
            this.data = data;
            this.prev = prev;
            this.next = next;
        }
    }

    @Override
    public Iterator<T> iterator() {
        return null;
    }

    @Override
    public void forEach(Consumer<? super T> action) {

    }

    @Override
    public Spliterator<T> spliterator() {
        return null;
    }
}
